package com.ldk.admin.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ldk.admin.constants.CONFIG;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class UserInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {

		//判断登录用户SESSION 是否过期
		if(request.getSession().getAttribute("user") == null){
			response.sendRedirect("");
			return false;
		}
		//设置查询者角色ID，偷懒设置成死的,现在数据里面是配置查询用户角色ID为3
		request.getSession().setAttribute("viewerRole", 3);
		request.getSession().setAttribute("companyRole", CONFIG.COMPANY_ROLEID);
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		
	}

}
